<?php

use swap\service_except;
use swap\visitor;

class user_service extends swap\service {

    // 关于user相关checker
    public static function check_captcha($captcha) {
        $used = visitor::get_role_var('guest', 'captcha_used');
        if ($used) {
            service_except::throw_prop_msg('validate', '验证码错误');
        }
        $captcha_memcached = visitor::get_role_var('guest', 'captcha');
        if ($captcha_memcached !== $captcha) {
            service_except::throw_prop_msg('validate', '验证码错误');
        }
    }

    // 格式化email, hinson0@qq.com => hinson0@qq.co...
    public static function format_email($email, $format_length = 15) {
        $email_length = strlen($email);
        if ($email_length > $format_length) {
            $_email = substr($email, 0, $format_length - 3) . '...';
        } else {
            $_email = $email;
        }
        return $_email;
    }

    // index.tpl所有的数据
    public static function get_index_data() {
        $resumes = resume_model::get(array('user_id' => visitor::get_role_id('user')), array(array('id' => 'desc'), 1, user_limit_model::resume));
        $index = array(
            'resumes' => $resumes,
        );
        return $index;
    }

}